<#include "layout/template.ftl"/>

<@htmlHead title="编辑权限">
  
</@htmlHead>


 
<@htmlBody 'system' 'permissionManage'>

	<!-- breadcrumbs begin -->
	<#include "layout/breadcrumbs.ftl">
	<@breadcrumbs '权限管理' '编辑权限'></@breadcrumbs>
	<!-- breadcrumbs end -->

	<!-- page-content begin -->
	<div class="page-content">
			
			<!-- page-header begin -->
			<div class="page-header">
					<h1>
						编辑权限
					</h1>
			</div>
			<!-- page-header end -->

			<!-- page-body begin -->
			<div class="row">	
				<div class="col-md-6 col-md-offset-3">
				
						<!-- 表单开始 -->
						<form class="form-horizontal" id="validation-form" method="post" action="${path}/manage/system/permission/update/${permission.id}" >
								<input type="hidden" name="id" value="${permission.id}"/>
								
					       		<div class="form-group">  
									<label class="control-label col-md-2">父级节点:</label>
									<div class="col-md-10">	
										<div class="clearfix">
											<select name="parent.id" id="parentid" class="form-control">
											<#list permissionList as p>
												<option value="${p.id}" ${(permission.parent.id==p.id)?string('selected','')}>${p.name}</option>	
											</#list>	
											</select>
										</div>
									</div>
								</div>
								
					       		<div class="form-group">
									<label class="control-label col-md-2">权限名称:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="form-control" placeholder="请输入权限名称" name="name"  id="name" value="${permission.name}" />
										</div>
									</div>
								</div>
								
								<div class="form-group">
									<label class="control-label col-md-2">权限描述:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="form-control" placeholder="请输入权限描述" name="description"  id="description" value="${permission.description}" />
										</div>
									</div>
								</div>
								
								<div class="form-group">
									<label class="control-label col-md-2">权限标示:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="form-control" placeholder="请输入权限标示" name="permission"  id="permission" value="${permission.permission}" />
										</div>
									</div>
								</div>
								
								<div class="form-group">
									<label class="control-label col-md-2">链接:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="form-control" placeholder="请输入链接" name="url"  id="url" value="${permission.url}" />
										</div>
									</div>
								</div>
								
								<div class="form-group">
									<label class="control-label col-md-2">排序:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="form-control" placeholder="请输入排序" name="seq"  id="seq" value="${permission.seq}" />
										</div>
									</div>
								</div>

								<div class="form-group">
									<label class="control-label col-md-2">是否显示:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<select name="state" id="state" class="form-control">
												<option value="open" ${(permission.state=='open')?string('selected','')}>显示</option>
												<option value="close" ${(permission.state=='close')?string('selected','')}>不显示</option>
											</select>
										</div>
									</div>
								</div>
								
								<div class="form-group">
									<label class="control-label col-md-2">资源类型:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<select name="type" id="type" class="form-control">
												<option value="1" ${(permission.type=='1')?string('selected','')}>菜单</option>
												<option value="2" ${(permission.type=='2')?string('selected','')}>按钮</option>
											</select>
										</div>
									</div>
								</div>
								
								<div class="form-group">
									<label class="control-label col-md-2">父节点标示:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="form-control" name="menuParent"  id="menuParent" value="${permission.menuParent}" />
										</div>
									</div>
								</div>
								
								
								<div class="form-group">
									<label class="control-label col-md-2">子节点标示:</label>
							
									<div class="col-md-10">
										<div class="clearfix">
											<input type="text" class="form-control"  name="menuChild"  id="menuChild" value="${permission.menuChild}" />
										</div>
									</div>
								</div>
								
								
								<div class="col-md-8 center">
		                    		<button type="submit" class="btn btn-primary">
										<i class="fa fa-save align-top bigger-125"></i>保存
									</button>
							 
									<button type="reset" class="btn">
										<i class="fa fa-pencil align-top bigger-125"></i>重置
									</button>
								</div>	
								
						</form>
						<!-- 表单结束 -->
						
	
				</div>
			</div>
			<!-- page-body end -->
		
	</div>		
	<!-- page-content end -->

</@htmlBody>



<@htmlBodyScript>

	<!-- ztree权限 -->
	<link href="${resources}/plugins/jquery-ztree/3.5.12/css/zTreeStyle/zTreeStyle.min.css" rel="stylesheet" type="text/css"/>
	<script src="${resources}/plugins/jquery-ztree/3.5.12/js/jquery.ztree.all-3.5.min.js" type="text/javascript"></script>
	<script>
			var setting = {
				check:{enable:true,nocheckInherit:true},
				view:{selectedMulti:false},
				data:{simpleData:{enable:true}},
				callback:{
					beforeClick:function(id, node){
						tree.checkNode(node, !node.checked, true, true);
						return false;
					}
				}
			};
	
			// 用户-菜单
			var zNodes=[
					<#list permissionList as permisssion>{id:"${permisssion.id}", pId:"${(permisssion.parent.id??)?string(permisssion.parent.id,0)}", name:"${permisssion.name}"},
		            </#list>];
			// 初始化树结构
			var tree = $.fn.zTree.init($("#permissionTree"), setting, zNodes);
			// 不选择父节点
			tree.setting.check.chkboxType = { "Y" : "ps", "N" : "s" };
			// 默认选择节点
			var ids = "${role.permissionIds}".split(",");
			for(var i=0; i<ids.length; i++) {
				var node = tree.getNodeByParam("id", ids[i]);
				try{tree.checkNode(node, true, false);}catch(e){}
			}
			// 默认展开全部节点
			tree.expandAll(true);
	</script>
	
	
	<!-- 上传控件 -->
	<script type="text/javascript" src="${resources}/assets/js/ajaxfileupload.js"></script>
	<script>
	    /**
	     * 功能 : 提交表单
		 */
	 	function mysubmit(form){
	 		$("#"+form).submit();
	 	}
	</script>

	<!-- 验证框架 -->	
	<script src="${resources}/plugins/jquery-validation/jquery.validate.min.js"></script>
	<script src="${resources}/plugins/jquery-validation/messages_zh.min.js"></script>
	<script type="text/javascript">

			jQuery.validator.addMethod("isName", function(value, element) {       
	 			var corpName =  /^[\u0391-\uFFE5\w\-\s\.]{1,50}$/;
  				 return this.optional(element) || corpName.test(value);       
 			}, "请使用汉字、英文字母、数字、下划线、减号、空格或点");   
 			
	
			$('#validation-form').validate({
				errorElement: 'div',
				errorClass: 'help-block',
				focusInvalid: false,
				rules: {
					name: {
						required:true,
						maxlength: 32
					},
					description: {
						maxlength: 255
					},
					permission: {
						maxlength: 255
					},
					url: {
						maxlength: 255
					},
					seq: {
						digits:true
					},
					state: {
						required:true
					},
					"parent.id": {
						required:true
					},
					type: {
						required:true
					},
					menuParent: {
						required:true,
						maxlength: 32
					}
				},
		
				messages: {
				},
		
		
				highlight: function (e) {
					$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
				},
		
				success: function (e) {
					$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
					$(e).remove();
				},
		
				errorPlacement: function (error, element) {
					if(element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
						var controls = element.closest('div[class*="col-"]');
						if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
						else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
					}
					else if(element.is('.select2')) {
						error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
					}
					else if(element.is('.chosen-select')) {
						error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
					}
					else error.insertAfter(element.parent());
				},
		
				submitHandler: function (form) {
					
					form.submit();
				},
				invalidHandler: function (form) {
				}
			});
	</script>

</@htmlBodyScript>